package cn.edu.aust.zhuzhang.mydialogtest.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.AssetFileDescriptor;
import android.util.Log;
import android.util.Xml;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.xmlpull.v1.XmlPullParser;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

import cn.edu.aust.zhuzhang.mydialogtest.R;
//import cn.edu.aust.zhuzhang.mydialogtest.model.UserInfo;

public class FileTool {
    public static int checkInSp(Context context, String username, String pwd){
        int result=-1;
        SharedPreferences sp=context.getSharedPreferences("spuser",Context.MODE_PRIVATE);
        String uname=sp.getString("username","");
        String upwd=sp.getString("pwd","");
        boolean nequals=uname.equals(username);
        boolean pequals=upwd.equals(pwd);
        if ( nequals&&pequals){
            result=0;
        }else if (nequals &&!pequals){
            result=1;//密码不对
        }else{
            result=2;//用户名不对
        }

        return result;
    }

    public static void writeUserIntoSp(Context context, String username, String pwd,String sex,String hobStr){
        SharedPreferences sp=context.getSharedPreferences("spuser",Context.MODE_PRIVATE);
        SharedPreferences.Editor editor=sp.edit();
        editor.putString("id","20190001001");
        editor.putString("username",username);
        editor.putString("pwd",pwd);
        editor.putString("sex",sex);
        editor.putString("hobbies",hobStr);
        editor.commit();
    }
}
